package com.sikao.app.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by y50 on 2016/5/2.
 */
public class TimeUtil {

	public static String fotmatString1 = "yyyy-MM-dd HH:mm:ss";
	public static String fotmatString2 = "yyyy-MM-dd HH:mm";
	public static String fotmatString3 = "yyyy/MM/dd HH:mm:ss";
	public static String fotmatString4 = "yyyy/MM/dd HH:mm";

	public static String getTime(){
		return System.currentTimeMillis()+"";
	}

	public static String timeToTimeStamp(String time,String type){
		SimpleDateFormat format =  new SimpleDateFormat(type);
		Date date = null;
		try {
			date = format.parse(time);
			return date.getTime()+"";
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return "时间类型有误";
	}
	public static long timeToTimeStampForLong(String time,String type){
		SimpleDateFormat format =  new SimpleDateFormat(type);
		Date date = null;
		try {
			date = format.parse(time);
			return date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return  0l;
	}
	public static String timeToTimeStampForSecond(String time,String type){
		SimpleDateFormat format =  new SimpleDateFormat(type);
		Date date = null;
		try {
			date = format.parse(time);
			String temp=date.getTime()+"";
			return  temp.substring(0,temp.length()-3);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return "0";
	}

	public static String timeStampToTime(String time,String type){
		SimpleDateFormat format =  new SimpleDateFormat(type);
		if (time.length() == 10){
			time = time + "000";
		}
		Long time1 = new Long(time);
		String d = format.format(time1);
		return d;
	}

}
